//
// Created by wsc on 2023/8/19.
#include "threads.h"
#include "convert_utils.h"
#include "main_widget_c.h"
#include "QtCore/QElapsedTimer"

ConvertThread::ConvertThread(Window *parent, const QString output_dir) {
    this->parent = parent;
    this->output_dir = output_dir;
}


void ConvertThread::run() {
    QElapsedTimer time;
    time.start();
    // 禁用按钮
    parent->ui.add_button->setEnabled(false);
    parent->ui.remove_button->setEnabled(false);
    parent->ui.convert_button->setEnabled(false);



    QStringList img_dirs = parent->list_model->stringList();
    float train_rate = parent->ui.train_rate->value();
    ConvertUtils::convert(img_dirs, train_rate, this->output_dir, parent);

    // 启用按钮
    parent->ui.add_button->setEnabled(true);
    parent->ui.remove_button->setEnabled(true);
    parent->ui.convert_button->setEnabled(true);

    // 计算耗时
    int ms = time.elapsed();
    emit parent->log_signal(QString("转换完成，耗时%1毫秒").arg(ms));
}
